<?php
	header('Content-Type:text/html;charset=utf-8');
	define('BASE_PATH',substr(dirname(__FILE__), 0,-5));
	include_once 'smarty/Smarty.class.php';

	class MyDB{
		protected $mypdo;
		protected $rows;
		protected $stmt;
		public function __construct(){
			try {
				$this->mypdo=new PDO("mysql:host=localhost;dbname=test", "root", "mysqladmin");
				$this->mypdo->query("set names utf8");
				return $this->mypdo;
			}catch (PDOException $e){
				$e->getMessage();
				exit();
			}
		}
		
		public function ExecSQL($sql){
			$sqltype=strtolower(substr(trim($sql),0,6));
			$this->stmt=$this->mypdo->prepare($sql);
			$this->rst=$this->stmt->execute();
			if($this->stmt->rowCount()!=0){
				$this->rows=$this->stmt->rowCount();
				if($sqltype="select"){
					return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
				}elseif ($sqltype=="update"||$sqltype=="insert"||$sqltype=="delete"){
					return true;
				}
			}else{
				return false;
			}
		}
		
		public function getRow(){
			return $this->rows;
		}
	}
	
	class MySmarty extends Smarty{
		function __construct(){
			parent::__construct();
			$this->template_dir=BASE_PATH;
			$this->compile_dir=BASE_PATH."/templates_c";
			$this->config_dir=BASE_PATH."/config";
			$this->cache_dir=BASE_PATH."/cache";
			$this->left_delimiter="<{";
			$this->right_delimiter="}>";
			$this->caching=false;
			$this->debugging=false;
		}
	}
	
	$smarty=new MySmarty();
	$conn=new MyDB();
?>